package com.woniuxy.happylife.suggest.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.woniuxy.happylife.entity.Business;
import com.woniuxy.happylife.entity.BusinessType;
import com.woniuxy.happylife.entity.ResponseEntity;
import com.woniuxy.happylife.suggest.service.BusinessService;
import com.woniuxy.happylife.suggest.service.BusinessTypeServie;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.Set;

/**
 * @Author Fu
 * @Date 2022-02-21 15:31
 */
@CrossOrigin
@RestController
@Slf4j
@RequestMapping("business")
public class BusinessController {
    @Resource
    BusinessService businessService;
    @Resource
    BusinessTypeServie businessTypeServie;
    @PostMapping("add")
    public ResponseEntity add(@RequestParam("file") MultipartFile[] files, String content, String orderNo, int businessType , Date createTime){
        /*for (MultipartFile file : files) {
            log.info(file.getOriginalFilename());
        }

        log.info(form.toString());*/
        Form form = new Form(content, orderNo, businessType,createTime);
        int i = businessService.insert(files,form);


        return null;
    }
    @GetMapping("findType")
    public ResponseEntity findType(){
       List<BusinessType> list = businessTypeServie.findType();
       if(list.size()>0){
           return new ResponseEntity(200,"查询成功",list);
       }
       return new ResponseEntity(400,"查询失败",null);
    }
    @GetMapping("findAll/{page}/{limit}")
    public  ResponseEntity findAll(@PathVariable("page") int page,@PathVariable("limit") int limit){
        PageHelper.startPage(page,limit);


        List<Business> list=businessService.findAll();
        if(list.size()>0){
            PageInfo<Business> pageInfo = new PageInfo<>(list);
            return new ResponseEntity(200,"查询成功",pageInfo);
        }
        return new ResponseEntity(400,"查询失败",null);
    }
    @PostMapping("findByCondition/{page}/{limit}")
    public ResponseEntity findByCondition(
            @PathVariable("page")int page,@PathVariable("limit")int limit,
            @RequestBody Business business){
        log.info(business.toString());
        PageHelper.startPage(page,limit);
        List<Business> list = businessService.findByCondition(business);
        PageInfo<Business> pageInfo = new PageInfo<>(list);
        if(list.size()>0){

            return new ResponseEntity(200,"查询成功",pageInfo);
        }
        return new ResponseEntity(400,"查询失败",pageInfo);

    }
}
